package com.pengshun.modules.api.user.controller;

import com.pengshun.modules.api.coal.validator.*;
import com.pengshun.modules.api.user.para.CarPara;
import com.pengshun.modules.api.user.service.UserCarService;
import com.pengshun.modules.api.user.service.dto.CarDrivingDto;
import com.pengshun.modules.api.user.service.dto.CarOwnerDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "车辆管理")
@RequestMapping("/api/car")
@ApiIgnore
public class UserCarController {

    private final UserCarService userCarService;
    @ApiOperation(value = "车辆列表",notes = "")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "status", value = "类型(1审核中,2通过审核,3审核失败)", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数", dataType = "int", required = true, paramType = "query"),

    })
    @Authorization
    public BaseResult detil(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) CarPara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userCarService.list(para);
        return res;
    }
    @ApiOperation(value = "添加车辆",notes = "carOwnerId 默认不传，修改或者重新提交在传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carOwnerId", value = "车主认证id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "carNumber", value = "车牌号", dataType = "string", required = true,paramType = "query"),
            @ApiImplicitParam(name = "typeName", value = "车辆类型", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "vehicleTypeId", value = "车辆类型ID", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "carPhoto", value = "车辆照片", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "carWight", value = "车重", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "carLoad", value = "载重", dataType = "string", required = true,paramType = "query"),
            @ApiImplicitParam(name = "carLength", value = "车辆长度", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "vehicleLengthId", value = "车辆长度id", dataType = "int", required = true,paramType = "query"),
            @ApiImplicitParam(name = "vehicleLicenseFirstPic", value = "行驶证主页", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "vehicleLicenseSecondPic", value = "行驶证副业", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "operatingFont", value = "运营正面", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "operatingBack", value = "运营副业", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "proveImage", value = "证明图", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "userType", value = "1司机,2车主,3运输公司", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "isSelf", value = "是否本人 0否 1是", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/update")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {First.class}) CarOwnerDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userCarService.update(para);
        return res;
    }
    @ApiOperation(value = "删除车辆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carOwnerId", value = "车主认证id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/delete")
    @Authorization
    public BaseResult delete(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Second.class}) CarOwnerDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userCarService.delete(para);
        return res;
    }
    @ApiOperation(value = "删除车辆司机关联")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carDrivingId", value = "车主认证id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/delete-associated")
    @Authorization
    public BaseResult associated(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Third.class}) CarOwnerDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userCarService.deleteAssociated(para);
        return res;
    }
    @ApiOperation(value = "车辆详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carOwnerId", value = "车主认证id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/detil")
    @Authorization
    public BaseResult detil(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Second.class}) CarOwnerDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userCarService.detil(para);
        return res;
    }
    @ApiOperation(value = "查询车辆未关联司机列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carOwnerId", value = "车主认证id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "1已关联 2未关联", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/car-list")
    @Authorization
    public BaseResult carList(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Fifth.class}) CarDrivingDto para) throws Exception {
        para.setCarUserId(user.getId());
        BaseResult res = userCarService.notBindingCarList(para);
        return res;
    }

}
